package com.shawn.baseappbygroovydsl.ui.view

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import com.google.android.material.tabs.TabLayout
import androidx.core.graphics.toColorInt
import com.shawn.baseappbygroovydsl.ui.extension.ExtensionCommon.appToastV2

/**
 * @author Secret
 * @since 2025/1/20
 */
class TabLayoutWithClickHolder @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : TabLayout(context, attrs) {

    var isDramaTabShowUp = false
    var showTTDramaCategory = true

    override fun selectTab(tab: Tab?, updateIndicator: Boolean) {
        if (tab?.position == if (showTTDramaCategory) {
                3
            } else {
                2
            }
        ) {
            val unlockChatTab = false
            if (unlockChatTab) {
                super.selectTab(tab, updateIndicator)
            } else {
                "业务需要拦截tab点击事件".appToastV2(context)
                return
            }
        } else {
            super.selectTab(tab, updateIndicator)
        }

        refreshTabUI(tab?.position ?: -1)

    }

    private fun refreshTabUI(tabPos: Int) {
        if (tabPos == -1) {
            return
        }
        setBackgroundColor(
            if (showTTDramaCategory) {
                when (tabPos) {
                    1 -> "#FF030100".toColorInt()
                    else -> Color.TRANSPARENT
                }
            } else {
                Color.TRANSPARENT
            }
        )
        if (showTTDramaCategory) {
            when (tabPos) {
                1 -> {
                    for (index in 0 until tabCount) {
                        getTabAt(index)?.customView?.let {

                        }
                    }
                }

                else -> {
                    for (index in 0 until tabCount) {
                        getTabAt(index)?.customView?.let {

                        }
                    }
                }
            }
        } else {
            for (index in 0 until tabCount) {
                getTabAt(index)?.customView?.let {

                }
            }
        }

    }

    fun refreshChatTabImage() {
        getTabAt(
            if (showTTDramaCategory) {
                3
            } else {
                2
            }
        )?.customView?.let {

        }
    }

}